/**
 * @file lavas config
 * @author zxy(yu26558@163.com)
 */

'use strict';

const path = require('path');
const SpritesmithPlugin = require('webpack-spritesmith');
const BUILD_PATH = path.resolve(__dirname, 'dist');
const isDev = process.env.NODE_ENV === 'development';
const isProd = process.env.NODE_ENV === 'production';

module.exports = {
    build: {
        ssr: false,
        path: BUILD_PATH,
        jsSourceMap: false,
        publicPath: '/',
        ssrCopy: isDev ? [] : [
            {
                src: 'server.prod.js'
            },
            {
                src: 'package.json'
            }
        ],
        plugins: {
            base: [new SpritesmithPlugin({
                // 目标小图标
                src: {
                    cwd: path.resolve(__dirname, './static/img/images/categorys'),
                    glob: '*.png'
                },
                // 输出雪碧图文件及样式文件
                target: {
                    image: path.resolve(__dirname, './static/img/sprites/sprite.png'),
                    css: path.resolve(__dirname, './static/img/sprites/sprite.css')
                },
                // 样式文件中调用雪碧图地址写法
                apiOptions: {
                    cssImageRef: '../sprites/sprite.png'
                },
                spritesmithOptions: {
                    algorithm: 'top-down',
                    padding: 4,
                }
            })],
        }
    },
    router: {
        mode: 'hash',
        base: '/',
        pageTransition: {
            type: 'fade',
            transitionClass: 'fade'
        },
        routes: [
            {
                pattern: '/sell',
                meta: {
                    keepAlive: true
                }
            },
            {
                pattern: '/buy-list',
                meta: {
                    keepAlive: true
                }
            },
            {
                pattern: '/compare-phone/compare-price',
                meta: {
                    keepAlive: true
                }
            },
            {
                pattern: '/compare-phone/phone-list',
                meta: {
                    keepAlive: true
                }
            },
            {
                pattern: '/compare-phone/phone-detail',
                meta: {
                    keepAlive: true
                }
            }
        ]
    },
    serviceWorker: {
        swSrc: path.join(__dirname, 'core/service-worker.js'),
        swDest: path.join(BUILD_PATH, 'service-worker.js'),
        // swPath: '/custom_path/', // specify custom serveice worker file's path, default is publicPath
        globDirectory: BUILD_PATH,
        globPatterns: [
            '**/*.{html,js,css,eot,svg,ttf,woff}'
        ],
        globIgnores: [
            'sw-register.js',
            '**/*.map'
        ],
        // appshellUrl: '/appshell',
        dontCacheBustUrlsMatching: /\.\w{8}\./
    }
};
